package com.chengshuang.log.context;

import java.util.ArrayList;
import java.util.List;

/**
 * 日志记录上下文
 **/
public class LogRecordContext {

    /**
     * 快照缓存
     */
    private static final ThreadLocal<List<Object>> SNAPSHOT_CACHE = ThreadLocal.withInitial(ArrayList::new);

    private LogRecordContext() {
    }

    public static void addSnapshotCache(Object object) {
        List<Object> snapshots = SNAPSHOT_CACHE.get();
        if (snapshots == null) {
            snapshots = new ArrayList<>(1);
        }
        snapshots.add(object);
        SNAPSHOT_CACHE.set(snapshots);
    }

    public static List<Object> getSnapshotCache() {
        return SNAPSHOT_CACHE.get();
    }

    public static void remove() {
        SNAPSHOT_CACHE.remove();
    }
}
